<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	
	<head>
		<meta http-equiv="Content-Language" content="en-gb" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Creating PDF documents" />
		<title>PDF Graphics .NET documentation - Creating PDF documents</title>
		<link rel="stylesheet" href="style/Help.css" type="text/css" />
	</head>
	
	<body>
		<div class="navigator">
			<span>
				<strong>PDF Graphics .NET</strong> :: <a href="Index.html">Help</a> :: Creating PDF documents
			</span>
		</div>
		
		<h1>Creating PDF documents</h1>
		
		<p>
			This section explains how to create PDF documents using PDF Graphics .NET. Read the sections below for
			an introduction to creating documents and pages.
		</p>
			
		<h2>Hello, World</h2>
		
		<p>
			Let's start by creating a document that displays the text 'Hello, World!'. See the code below:
		</p>
		
		<div class="sampleCode">include PdfCreative.Pdf.Graphics;

class HelloWorld
{
    public static void Main(int[] args)
    {
        Graphics g = new Graphics("HelloWorld.pdf");
        Font font = new Font("Times New Roman");
		
        g.DrawString(Rgb.BlackBrush, "Hello, World!", font, 10f, 0, 0);
        
        g.Close();
    }
}</div>
		
		<p>
			This code will create a new PDF document with the sentence 'Hello, World!' in the top-left hand corner of
			the page.
		</p>
		
		<p>
			It starts off by including the <span class="code">PdfCreative.Pdf.Graphics</span> namespace, which will save us a bit of
			typing later on. Most of the classes in PDF Graphics .NET can be found in that namespace.
		</p>
		
		<p>
			The first line in the <span class="code">Main()</span> method creates a new <span class="code">Graphics</span> object,
			and tells it to write to a file called <span class="code">HelloWorld.pdf</span>.
		</p>
		<p>
			After that, the second line creates a new font that uses the Times New Roman type. Note that unlike some graphics
			libraries, such as <span class="code">System.Drawing</span> in the .NET Framework, the size of the font is not
			part of the font definition. Only the type name is.
		</p>
		
		<p>
			The statement in line 3 draws the 'Hello, World!' text onto the page. The text will appear in the top-left hand corner
			of the page. Just like with <span class="code">System.Drawing</span>, the coordinate system is based on the top-left
			hand corner, so graphics are drawn to the right and down the page.
			The text is drawn with a black brush, at 10 points. For more information on colours and font sizes, see the
			<a href="Painting_Graphics.html">Painting Graphics</a> section of this documentation.
		</p>
		
		<p>
			And finally, the last line closes the <span class="code">Graphics</span> object and finalises the PDF document. It is important to always call
			the <span class="code">Close()</span> method, or else no PDF file will be created.
		</p>
				
		<h2>Creating pages</h2>
		
		<p>
			As the 'Hello, World!' example shows, it is not necessary to explicitly create the first page in your document; one will
			be created for you. However, to manually create a page, and create subsequent ones, the <span class="code">Graphics</span> class
			has a <span class="code">NewPage()</span> method to do just that. See the example below (classes and methods omitted for brevity);
		</p>
		
		<div class="sampleCode">Graphics g = new Graphics("ManyPages.pdf");
Font font = new Font("Times New Roman");

g.NewPage();
g.DrawString(Rgb.BlackBrush, "Page 1", font, 10f, 5, 5);

g.NewPage();	
g.DrawString(Rgb.BlackBrush, "Page 2", font, 14f, 5, 5);

g.NewPage();	
g.DrawString(Rgb.BlackBrush, "Page 3", font, 20f, 5, 5);

g.Close();</div>
				
		<p>
			This example code creates three pages, and writes some text on each. Note that the same font object is used throughout the
			PDF document; there is no need to instantiate a new one for every page you create.
		</p>
		
		<p>
			The <span class="code">NewPage()</span> method has several overloads that allow you to specify the kind of page
			you like. For example, to create a DIN A3 page, use the following statement:
		<p>
			
		<div class="sampleCode">g.NewPage(StandardPages.A3);</div>
		
		<p>
			For information on more advanced page creation, including their orientation in a PDF Viewer application, see the
			<a href="Advanced_use.html">Advanced use</a> section.
		</p>	
			
		<h3><strong>Navigation options:</strong></h3>
		<p><a href="Setting_up.html">&lt; Setting up</a> | <a href="Painting_graphics.html">Painting graphics &gt;</a>
				
	</body>
	
</html>